/*
DATE: 2021/12/07
AUTHOR: chenyihui
Desc:  初始化

*/
package dingtalk

import (
	"crypto/tls"
	"os"

	"net"
	"net/http"
	"time"
)

func Init() {
	// 获取配置
	dingTalk.token, dingTalk.secret = getConf()

	// 初始化http.Client参数
	dingTalk.httpCli = initHttpCli()
}

func getConf() (string, string) {

	token := os.Getenv("ding-token")
	// 获取配置
	if token == "" {
		panic("ding talk token is null")
	}

	secret := os.Getenv("ding-secret")
	return token, secret
}

func initHttpCli() *http.Client {
	return &http.Client{
		Transport: &http.Transport{
			MaxIdleConnsPerHost:   10,
			ResponseHeaderTimeout: time.Second * 10,
			DialContext:           (&net.Dialer{Timeout: time.Second * 5}).DialContext,
			TLSClientConfig: &tls.Config{
				MinVersion: tls.VersionTLS11,
			},
		},
		Timeout: 10 * time.Second,
	}
}
